package main

import "fmt"

func main() {
	fmt.Println(isValid("]"))
}

func isValid(s string) bool {
	pairs := map[byte]byte{
		')': '(',
		']': '[',
		'}': '{',
	}
	stack := make([]byte, 0)
	for _, item := range s {
		if v, ok := pairs[byte(item)]; ok {
			if len(stack) == 0 || v != stack[len(stack)-1] {
				return false
			} else {
				stack = stack[:len(stack)-1]
			}
		} else {
			stack = append(stack, byte(item))
		}
	}
	if len(stack) != 0 {
		return false
	}
	return true
}
